% 程序先生成直径为D的圆内的泽尼克多项式ZM
% 然后在通过非迭代矩阵法构造位于该圆域内的任意正交多项式FM
% Benchu Lu, benchuul@163.com
% Taiyuan University of Technology
% References:  
% OL: Nonrecursive determination of orthonormal polynomials with matrix formulation
% JOSA: Orthonormal polynomials in wavefront analysis: analytical solution
clear;close all;clc
D = 2; % 圆的直径
N = 128; % 采样点数
j_max = 20; % 计算前j_max项泽尼克多项式

% 在直径为D的圆域内生成任意形状的mask采样点阵
% 以方形为例
x = linspace(-D/2,D/2,N); [X,Y] = meshgrid(x,x);
mask_square = logical(((abs(X)<=D/2/sqrt(2)).*(abs(Y)<=D/2/sqrt(2))));
S = (D/sqrt(2))^2; % 面积

% 计算泽尼克多项式
ZM = ZernikeCal(j_max, D, N);
% 计算正交矩阵
M = OrthogonalMatrix(ZM, D, mask_square, S);
% 计算mask_square范围内的正交多项式
FM = ZM2FM(M, ZM, mask_square);


